#include "SecurityService.h"

SecurityService::SecurityService(){
    m_loaded = false;
}

 bool SecurityService::isLoaded(){
    return m_loaded;
}

bool SecurityService::getSecurityByCode(String code, Security *security)
{
    if (!m_loaded)
    {
        return false;
    }
    String key = FCTran::toUpper(code);
    key = FCTran::replace(key, L"\r", L"");
    key = FCTran::replace(key, L"\n", L"");
    if (m_securitiesMap.containsKey(code))
    {
        *security = *m_securitiesMap.get(code);
        return true;
    }
    else
    {
        return false;
    }
}
void SecurityService::load(ArrayList<Security*> securitiesCache)
{
    m_securities.clear();
    m_securitiesMap.clear();
    int securitiesSize = securitiesCache.size();
    for (int i = 0; i < securitiesSize; i++)
    {
        Security *security = securitiesCache.get(i);
        m_securities.add(security);
        m_securitiesMap.put(FCTran::toUpper(security->m_code), security);
    }
    securitiesCache.clear();
    m_loaded = true;
}
